using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace LS.GameKit
{
    [RequireComponent(typeof(Animator))]
    public class AnimatorControl : ControlBehaviour
    {
        private Animator m_Animator;

        public Animator Animator
        {
            get { return m_Animator; }
        }
        
        protected override void Awake()
        {
            base.Awake();
            m_Animator = GetComponent<Animator>();
        }

        public override void Preform(params object[] args)
        {
            if (args == null || args.Length == 0)
            {
                Debug.LogWarning($"Args is null or empty!");
                return;
            }

            AnimateStatus status = AnimateStatus.Unknow;
            int subStatus = 0;
            
            if (args[0] is AnimateStatus || args[0] is int)
            {
                status =  (AnimateStatus)args[0];
            }

            if (args.Length > 1 && args[1] is int)
            {
                subStatus =  (int)args[1];
            }

            if (status != AnimateStatus.Unknow)
            {
                SetState(status, subStatus);
            }
        }

        public void SetStatus(AnimateStatus status)
        {
            SetState(status, 0);
        }

        public AnimateStatus GetStatus()
        {
            return (AnimateStatus)m_Animator.GetInteger("AnimateStatus");
        }

        public int GetSubStatus()
        {
            return m_Animator.GetInteger("SubStatus");
        }
        
        public void SetState(AnimateStatus status, int subStatus)
        {
            if (status != AnimateStatus.Unknow)
            {
                Animator.SetInteger("AnimateStatus", (int)status);
                Animator.SetInteger("SubStatus", subStatus);
            }
        }
    }
}
